home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Finder Dungeon / source code / MoreFiles 1.4.6 / C Headers / FullPath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-28  |  8.5 KB  |  233 lines  |  [TEXT/MPS ]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Routines for dealing with full pathnames... if you really must.
  5. **
  6. **    by Jim Luther, Apple Developer Technical Support Emeritus
  7. **
  8. **    File:        FullPath.h
  9. **
  10. **    Copyright © 1995-1996 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  17. **    after having made changes. If you're going to re-distribute the source,
  18. **    we require that you make it clear in the source that the code was
  19. **    descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. #ifndef __FULLPATH__
  23. #define __FULLPATH__
  24.  
  25. #include <Types.h>
  26. #include <Files.h>
  27.  
  28. #include "Optimization.h"
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. /*
  35.     IMPORTANT NOTE:
  36.     
  37.     The use of full pathnames is strongly discouraged. Full pathnames are
  38.     particularly unreliable as a means of identifying files, directories
  39.     or volumes within your application, for two primary reasons:
  40.     
  41.     •     The user can change the name of any element in the path at
  42.         virtually any time.
  43.     •    Volume names on the Macintosh are *not* unique. Multiple
  44.         mounted volumes can have the same name. For this reason, the use of
  45.         a full pathname to identify a specific volume may not produce the
  46.         results you expect. If more than one volume has the same name and
  47.         a full pathname is used, the File Manager currently uses the first
  48.         mounted volume it finds with a matching name in the volume queue.
  49.     
  50.     In general, you should use a file’s name, parent directory ID, and
  51.     volume reference number to identify a file you want to open, delete,
  52.     or otherwise manipulate.
  53.     
  54.     If you need to remember the location of a particular file across
  55.     subsequent system boots, use the Alias Manager to create an alias
  56.     record describing the file. If the Alias Manager is not available, you
  57.     can save the file’s name, its parent directory ID, and the name of the
  58.     volume on which it’s located. Although none of these methods is
  59.     foolproof, they are much more reliable than using full pathnames to
  60.     identify files.
  61.     
  62.     Nonetheless, it is sometimes useful to display a file’s full pathname
  63.     to the user. For example, a backup utility might display a list of full
  64.     pathnames of files as it copies them onto the backup medium. Or, a
  65.     utility might want to display a dialog box showing the full pathname of
  66.     a file when it needs the user’s confirmation to delete the file. No
  67.     matter how unreliable full pathnames may be from a file-specification
  68.     viewpoint, users understand them more readily than volume reference
  69.     numbers or directory IDs. (Hint: Use the TruncString function from
  70.     TextUtils.h with truncMiddle as the truncWhere argument to shorten
  71.     full pathnames to a displayable length.)
  72.     
  73.     The following technique for constructing the full pathname of a file is
  74.     intended for display purposes only. Applications that depend on any
  75.     particular structure of a full pathname are likely to fail on alternate
  76.     foreign file systems or under future system software versions.
  77. */
  78.  
  79. /*****************************************************************************/
  80.  
  81. pascal    OSErr    GetFullPath(short vRefNum,
  82.                             long dirID,
  83.                             ConstStr255Param name,
  84.                             short *fullPathLength,
  85.                             Handle *fullPath);
  86. /*    ¶ Get a full pathname to a volume, directory or file.
  87.     The GetFullPath function builds a full pathname to the specified
  88.     object. The full pathname is returned in the newly created handle
  89.     fullPath and the length of the full pathname is returned in
  90.     fullPathLength. Your program is responsible for disposing of the
  91.     fullPath handle.
  92.     
  93.     vRefNum            input:    Volume specification.
  94.     dirID            input:    Directory ID.
  95.     name            input:    Pointer to object name, or nil when dirID
  96.                             specifies a directory that's the object.
  97.     fullPathLength    output:    The number of characters in the full pathname.
  98.                             If the function fails to create a full
  99.                             pathname, it sets fullPathLength to 0.
  100.     fullPath        output:    A handle to the newly created full pathname
  101.                             buffer. If the function fails to create a
  102.                             full pathname, it sets fullPath to NULL.
  103.     
  104.     Result Codes
  105.         noErr                0        No error    
  106.         nsvErr                -35        No such volume
  107.         ioErr                -36        I/O error
  108.         bdNamErr            -37        Bad filename
  109.         fnfErr                -43        File or directory does not exist
  110.         paramErr            -50        No default volume
  111.         memFullErr            -108    Not enough memory
  112.         dirNFErr            -120    Directory not found or incomplete pathname
  113.         afpAccessDenied        -5000    User does not have the correct access
  114.         afpObjectTypeErr    -5025    Directory not found or incomplete pathname
  115.     
  116.     __________
  117.     
  118.     See also:    FSpGetFullPath
  119. */
  120.  
  121. /*****************************************************************************/
  122.  
  123. pascal    OSErr    FSpGetFullPath(const FSSpec *spec,
  124.                                short *fullPathLength,
  125.                                Handle *fullPath);
  126. /*    ¶ Get a full pathname to a volume, directory or file.
  127.     The GetFullPath function builds a full pathname to the specified
  128.     object. The full pathname is returned in the newly created handle
  129.     fullPath and the length of the full pathname is returned in
  130.     fullPathLength. Your program is responsible for disposing of the
  131.     fullPath handle.
  132.     
  133.     spec            input:    An FSSpec record specifying the object.
  134.     fullPathLength    output:    The number of characters in the full pathname.
  135.                             If the function fails to create a full pathname,
  136.                             it sets fullPathLength to 0.
  137.     fullPath        output:    A handle to the newly created full pathname
  138.                             buffer. If the function fails to create a
  139.                             full pathname, it sets fullPath to NULL.
  140.     
  141.     Result Codes
  142.         noErr                0        No error    
  143.         nsvErr                -35        No such volume
  144.         ioErr                -36        I/O error
  145.         bdNamErr            -37        Bad filename
  146.         fnfErr                -43        File or directory does not exist
  147.         paramErr            -50        No default volume
  148.         memFullErr            -108    Not enough memory
  149.         dirNFErr            -120    Directory not found or incomplete pathname
  150.         afpAccessDenied        -5000    User does not have the correct access
  151.         afpObjectTypeErr    -5025    Directory not found or incomplete pathname
  152.     
  153.     __________
  154.     
  155.     See also:    GetFullPath
  156. */
  157.  
  158. /*****************************************************************************/
  159.  
  160. pascal OSErr FSpLocationFromFullPath(short fullPathLength,
  161.                                      const void *fullPath,
  162.                                      FSSpec *spec);
  163. /*    ¶ Get a FSSpec from a full pathname.
  164.     The FSpLocationFromFullPath function returns a FSSpec to the object
  165.     specified by full pathname. This function requires the Alias Manager.
  166.     
  167.     fullPathLength    input:    The number of characters in the full pathname
  168.                             of the target.
  169.     fullPath        input:    A pointer to a buffer that contains the full
  170.                             pathname of the target. The full pathname
  171.                             starts with the name of the volume, includes
  172.                             all of the directory names in the path to the
  173.                             target, and ends with the target name.
  174.     spec            output:    An FSSpec record specifying the object.
  175.     
  176.     Result Codes
  177.         noErr                0        No error
  178.         nsvErr                -35        The volume is not mounted
  179.         fnfErr                -43        Target not found, but volume and parent
  180.                                     directory found
  181.         paramErr            -50        Parameter error
  182.         usrCanceledErr        -128    The user canceled the operation
  183.     
  184.     __________
  185.     
  186.     See also:    LocationFromFullPath
  187. */
  188.  
  189. /*****************************************************************************/
  190.  
  191. pascal OSErr LocationFromFullPath(short fullPathLength,
  192.                                   const void *fullPath,
  193.                                   short *vRefNum,
  194.                                   long *parID,
  195.                                   Str31 name);
  196. /*    ¶ Get an object's location from a full pathname.
  197.     The LocationFromFullPath function returns the volume reference number,
  198.     parent directory ID and name of the object specified by full pathname.
  199.     This function requires the Alias Manager.
  200.     
  201.     fullPathLength    input:    The number of characters in the full pathname
  202.                             of the target.
  203.     fullPath        input:    A pointer to a buffer that contains the full
  204.                             pathname of the target. The full pathname starts
  205.                             with the name of the volume, includes all of
  206.                             the directory names in the path to the target,
  207.                             and ends with the target name.
  208.     vRefNum            output:    The volume reference number.
  209.     parID            output:    The parent directory ID of the specified object.
  210.     name            output:    The name of the specified object.
  211.     
  212.     Result Codes
  213.         noErr                0        No error
  214.         nsvErr                -35        The volume is not mounted
  215.         fnfErr                -43        Target not found, but volume and parent
  216.                                     directory found
  217.         paramErr            -50        Parameter error
  218.         usrCanceledErr        -128    The user canceled the operation
  219.     
  220.     __________
  221.     
  222.     See also:    FSpLocationFromFullPath
  223. */
  224.  
  225. /*****************************************************************************/
  226.  
  227. #ifdef __cplusplus
  228. }
  229. #endif
  230.  
  231. #include "OptimizationEnd.h"
  232.  
  233. #endif    /* __FULLPATH__ */